<!--受理订单列表-->
<template>
  <div class="d-contain">
    <div class="listhead-fix">
      <!--search-->
      <div class="m-sech-wrap mr20">
        <!-- <div class="flex1"> -->
          <router-link to='/search?type=LogisticOrder' class="m-sech-box displayflex">
            <i class="iconfont icon-search"></i>
            <div class="flex1 m-sech-ipt">
              <div class="txt">{{sechTxt || '输入客户名称或单号'}}</div>
            </div>
          </router-link>
        <!-- </div> -->
        <!-- <router-link to="/order/placeOrder" class="m-sech-classfiy">
          <i class="iconfont icon-add"></i>
          <p>新增</p>
        </router-link> -->
      </div>
      <!--tab-->
    </div>
    <div class="noDate_page" v-if="todolist.length <= 0">
      <div class="noDate_icon"><i class="iconfont icon-null"></i></div>
      暂无数据！
    </div>
    <scroller lock-x scrollbar-y use-pullup height="-116" class='scroller-wrap70' @on-pullup-loading="getData" v-if="todolist.length>0" :pullup-config="ScrollerConfig" ref="Scroller">
      <div class="acpt-list">
        <div class="acpt-list-wrap mb30" v-for="item in todolist">
          <div class="acpt-list-head cf">
            <span class="time f-l">{{item.BillDate | timeshort}}</span>
            <em class="org f-r ft12">{{item.BillState | billstate}}</em><!--{{item.MainPoState}}-->
          </div>
          <div class="displayflex acpt-list-body">
            <i class="iconfont icon-cargo"></i>
            <div class="txt flex1" @click="goProgress(item)">
              <p class="ft17">{{item.MedName}}</p>
              <p>{{item.BillNo}}</p>
              <p>{{item.Province | province}} {{item.City | city}} {{item.District | district}} {{item.Address}}</p>
              <p>品种数：{{item.CountSum}}个</p>
            </div>
          </div>
        </div>
      </div>
      <div v-if="noMore" class="loader-over">没有更多记录了</div>
    </scroller>
    <manage-footer></manage-footer>
  </div>
</template>

<script>
import manageFooter from '@/components/core/footer/manage.footer.vue';
export default {
  name:'acceptList',
  components: {
    manageFooter
  },
  data() {
    return {
      sechTxt:'',
      PageIndex: 1,
      PageSize:4,
      todolist:[],
      totalRecords:'',
      noMore:false,
      billState:'',
      ScrollerConfig:{
        content: '上拉加载',
        downContent: '上拉加载',
        height: 0,
        loadingContent: '加载中...',
        upContent: '上拉加载',
      }
    }
  },
  created(){
    this.sechTxt = sessionStorage.sechtxt;
    this.getData(1);
  },
  watch: {
    
  },
  computed: {
    userinfo(){
      return localStorage.getItem('userinfo') === null?null:JSON.parse(localStorage.getItem('userinfo'));
    }
  },
  mounted() {
    this.$nextTick(function() {
    })
  },
  methods: {
    getData(type){
      if (type == 1) {
        this.PageIndex = 1;
        this.todolist = [];
      }

      let MedGuid = '',
          BuyerGUID = this.userinfo.StaffID;

      if (this.userinfo.UserBizType=='Hospital') {
        MedGuid = this.userinfo.BelongGuid;
        BuyerGUID = '';
      }
      if (this.userinfo.UserBizType=='ServiceManager') {
         BuyerGUID = '';
      }

      var query = {
        KeyWord:this.sechTxt,
        MedGuid:MedGuid,
        BuyerGUID: BuyerGUID,
        CorpGuid: this.userinfo.CorpGuid,
        TenantGuid: this.userinfo.TenantGuid,
        PageIndex: this.PageIndex,
        PageSize: this.PageSize
      };

      this.Ajax.post('SearchLogisticOrder',query).then((resp) => {
        if (resp.IsSuccess) {
          this.totalRecords = resp.TotalRecords;
          if(resp.Datas && resp.Datas.length > 0){
            this.PageIndex++;
            this.todolist = this.todolist.concat(resp.Datas);
            this.ScrollControl();
          }
        } else {
          this.Toast({
              message: '列表为空，请稍后刷新',
          });
        }
      });
    }, 

    goProgress(item) {
      this.$router.push({
        path: '/order/progress',
        query:{
          Guid: item.Guid,
          MainPoGuid: item.MainPoGuid,
          BBillGuid: item.BBillGuid,
        }
      });
    },

    ScrollControl(){
      if(this.totalRecords <= this.PageSize){
        this.ScrollerConfig.content = '';
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.disablePullup();
            this.noMore = true;
          });
        });
      }

      if(this.todolist.length > 0 && this.$refs.Scroller){
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.donePullup();
          });
        });
      }

      if (this.totalRecords == this.todolist.length) {
        this.$nextTick(() => {
          this.$nextTick(() => {
            this.$refs.Scroller.disablePullup();
            this.noMore = true;
          });
        });
      }
    }
  }
}
</script>